import java.util.Scanner;
import java.util.*;
public class MC0410拯救圣莲池2 {
    static int  n;
    static long  k;
    static long [] a;
    public static void main(String[] args) {
    Scanner input = new Scanner(System.in);
    // code here
    n = input.nextInt();
    k = input.nextLong();
    a = new long[n];
    long maxVal = 0;
    for (int i = 0; i < n; i++) {
        a[i] = input.nextLong();
        maxVal = Math.max(maxVal, a[i]);
    }
    long r = maxVal + 1 ,l = 0;
    long boundaryM = 0; // 用于存储最终找到的分界点
    while(l < r){
        long mid = l + (r - l) / 2;
        if (check(mid)){
            boundaryM = mid;// 把它作为备选答案
            l = mid+1;
        }else {
            r = mid;
        }
    }// 计算逻辑
        long totalPower = 0;
        long usedK = 0;
        for (int i = 0; i < n; i++) {
            if (a[i] > boundaryM){
                long count = a[i] - boundaryM;
                totalPower += calc(a[i], count);
                usedK += count;
            }
        }
        long remainingK = k - usedK;
        if (remainingK > 0) {
            // 剩余机会的收益
            totalPower += remainingK * boundaryM;
        }
    System.out.println(totalPower);
    input.close();
}

    /**
     * 这是一个计算等差数列和的辅助函数。
     * 作用：计算从 n 开始，递减 1，共 k 项的和。
     * 即：n + (n-1) + (n-2) + ... + (n-k+1)
     * 根据等差数列求和公式：(首项 + 末项) * 项数 / 2
     * 首项 = n
     * 末项 = n - (k - 1) = n - k + 1
     * 和 = (n + (n - k + 1)) * k / 2 = (2*n - k + 1) * k / 2
     *
     * @param n 首项
     * @param k 项数
     * @return 等差数列的和
     */
    public static long calc(long n,long k){
        return (2 * n - k + 1) * k / 2;
    }
    public static boolean check(long mid){
        long res = 0;
        for (int i = 0; i < n; i++) {
            if(a[i] >= mid){
                res += (a[i] - mid + 1);
            }
        }
        return res >= k;
    }
}
